 <?php
class Album extends Model_Abstract
{
	public $tableName = 'albums';
	
	
	protected $_validation = array(
		'albumname' => array(
			array('max_length', '相册名不能超过100个字符', 100),
			array('not_empty', '相册名不能为空')
		),
		'describe' => array(
			array('max_length', '请在200个字以内简述相册', 200),
		),
		'uid' => array(
			array('is_int', 'uid不正确'),
			array('not_empty', '请登录')
		)
	);
	
	public function attributeLabels()
	{
		return array(
			'albumname' => '相册名',
			'describe' => '描述'
		);
	}

	protected function validate()
	{
		$ret = true;
		
		$ret2 = parent::validate();
		
		return ($ret && $ret2);
	}
	
	public function createDefaultAlbum($user)
	{
		if($user){
			$defaultAlbum = array(
				'albumname' => $user['nickname'] . '的相册',
				'`describe`' => '默认相册',
				'uid' => $user['id'],
				'`create`' => date('Y-m-d H:i:s')
			);
			$this->attributes = $defaultAlbum;
			return $this->save();
		}
		
		return false;
	}

	public function checkAlbumOwn($uid)
	{
		if(empty($this->attributes['id'])){
			return false;
		}
		$result = $this->count(array('id' => $this->attributes['id'], 'uid' => $uid));
		if($result > 0){
			return true;
		}
		
		return false;
	}

}